import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '部门名称',
    align: 'left',
    dataIndex: 'name',
    width: 280
   },
   
   {
    title: '医院ID',
    align: 'center',
    dataIndex: 'hospitalId',
    width: 200
   },
   {
    title: '医院名称',
    align: 'center',
    dataIndex: 'hospitalName',
    width: 250
   },
   {
    title: '创建人',
    align: 'center',
    dataIndex: 'createBy'
   },
   {
    title: '创建日期',
    align: 'center',
    dataIndex: 'createTime'
   },
   {
    title: '更新人',
    align: 'center',
    dataIndex: 'updateBy'
   },
   {
    title: '更新日期',
    align: 'center',
    dataIndex: 'updateTime'
   },

];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "部门名称",
      field: "name",
      component: 'Input',
      //colProps: {span: 6},
     },
	{
      label: "医院ID",
      field: "hospitalId",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"nurse_hospital,name,id"
      },
      //colProps: {span: 6},
     },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '部门名称',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入部门名称!'},
          ];
     },
  },
  {
    label: '父级节点',
    field: 'pid',
    component: 'JTreeSelect',
    componentProps: {
      dict: "nurse_dept,name,id",
      pidField: "pid",
      pidValue: "0",
      hasChildField: "has_child",
    },
  },
  {
    label: '医院',
    field: 'hospitalId',
    component: 'JDictSelectTag',
    componentProps: ({ formActionType }) => {
      return {
        dictCode: "nurse_hospital,name,id",
        onChange: async (value) => {
          console.log('医院选择改变:', value);
          // 获取医院名称
          const { initDictOptions } = await import('/@/utils/dict');
          const dictData = await initDictOptions('nurse_hospital,name,id');
          const hospital = dictData.find(item => item.value === value);
          if (hospital) {
            const hospitalName = hospital.text || hospital.label;
            console.log('写入医院名称:', hospitalName);
            formActionType.setFieldsValue({ hospitalName: hospitalName });
          }
        }
      };
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请选择医院!'},
          ];
     },
  },
  {
    label: '医院名称',
    field: 'hospitalName',
    component: 'Input',
    componentProps: {
      disabled: true,
      placeholder: '选择医院后自动填充',
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  createBy: {title: '创建人',order: 0,view: 'text', type: 'string',},
  createTime: {title: '创建日期',order: 1,view: 'datetime', type: 'string',},
  updateBy: {title: '更新人',order: 2,view: 'text', type: 'string',},
  updateTime: {title: '更新日期',order: 3,view: 'datetime', type: 'string',},
  name: {title: '部门名称',order: 4,view: 'text', type: 'string',},
  pid: {title: '父级节点',order: 5,view: 'text', type: 'string',},
  hospitalId: {title: '医院ID',order: 6,view: 'list', type: 'string',dictTable: "nurse_hospital", dictCode: 'id', dictText: 'name',},
};


/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
